<template>
  <div>
    <el-row class="operate-padding border">
      <el-select v-model="value" class="m-2" placeholder="请选择课程教练">
        <el-option
          v-for="item in coach.coachList"
          :key="item.name"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
      <el-button class="dxk-12 button-left button-text-color3" @click="query"
        >查询</el-button
      >
      <el-button @click="dialogTableVisible = true" class="button-text-color3">
        添加排期
      </el-button>
    </el-row>
    <!-- 模态 -->
    <el-row>
      <el-dialog
        v-model="dialogTableVisible"
        title="添加排期"
        class="model-121"
      >
        <el-form
          ref="ruleFormRef"
          :model="ruleForm"
          :rules="rules"
          label-width="120px"
          class="demo-ruleForm"
          :size="formSize"
          status-icon
        >
          <el-form-item label="场馆选择" prop="region">
            <el-select v-model="ruleForm.region" placeholder="选择场馆">
              <el-option label="Zone one" value="shanghai" />
              <el-option label="Zone two" value="beijing" />
            </el-select>
          </el-form-item>
          <el-form-item label="场地" prop="region1">
            <el-select v-model="ruleForm.region1" placeholder="选择场地">
              <el-option label="Zone one" value="shanghai" />
              <el-option label="Zone two" value="beijing" />
            </el-select>
          </el-form-item>
          <el-form-item label="课程起始时间" prop="region1">
            <div class="example-basic">
              <el-time-picker v-model="value1" placeholder="00:00:00" />
              <el-time-picker
                v-model="value2"
                arrow-control
                placeholder="00:00:00"
                class="time-select-1"
              />
            </div>
          </el-form-item>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column label="星期一">
              <template #default>
                <el-select v-model="ruleForm.region3" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region4"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期二">
              <template #default>
                <el-select v-model="ruleForm.region5" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region6"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期三">
              <template #default>
                <el-select v-model="ruleForm.region7" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region8"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期四">
              <template #default>
                <el-select v-model="ruleForm.region9" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region10"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期五">
              <template #default>
                <el-select v-model="ruleForm.region11" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region12"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
          </el-table>
          <el-form-item>
            <el-button type="primary" @click="submitForm(ruleFormRef)"
              >Create</el-button
            >
            <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-row>
    <el-row class="lessons-padding1">
      <el-button type="primary" class="button-text-color"
        ><router-link to="/mainView/teamManagement/ScheduleView/CalendarView"
          >日历</router-link
        ></el-button
      >
      <el-button class="button-text-color2"
        ><router-link to="/mainView/teamManagement/ScheduleView/ListView"
          >列表</router-link
        ></el-button
      >
    </el-row>
    <el-row class="List-title"> 课程列表 </el-row>
    <el-row>
      <el-table :data="state.tableData" border style="width: 100%">
        <el-table-column prop="className" label="课程名称" />
        <el-table-column prop="coachName" label="教练" />
        <el-table-column prop="venueFieldName" label="场馆" />
        <el-table-column prop="venueName" label="场地" />
        <el-table-column prop="time" label="课程时间">
          <template #default="scope">
            <span class="line-break">{{ scope.row.day }}</span>
            <span class="line-break"
              >{{ scope.row.startTime }}-{{ scope.row.endTime }}</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="maxPeople" label="预约人数" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <!-- <el-button
              link
              type="primary"
              size="small"
              @click="dialogTableVisible = true"
              >编辑</el-button
            > -->
            <el-button
              link
              type="primary"
              size="small"
              @click="appointmentRecord(scope.row.id)"
              >预约记录></el-button
            >
            <el-button
              link
              type="primary"
              size="small"
              @click="handleClick(scope.row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from "vue";
import { findCourseList, findCoach,deleteCourseList} from "../../http/api";
import type { FormInstance, FormRules } from "element-plus";
import router from "../../router";
var state = reactive({ tableData: [] });
// 教练
var coach = reactive({ coachList: [] });
// 获取列表
onMounted(() => {
  findCourseList({ startDate: "10-17", coachId: value.value }).then((res) => {
    state.tableData = res;
    console.log(state.tableData);
  });
  // 获取教练列表
  findCoach().then((res:any) => {
    if (res.code == 0) {
      coach.coachList = res.data;
    }
  });
});
// 预约记录
const appointmentRecord = (id) => {
  router.push({
    path: "/mainView/AppointmentRecords",
    query: { zid: id },
  });
};

const value = ref("");
// 模态表单
const dialogTableVisible = ref(false);
const value1 = ref();
const value2 = ref();
const formSize = ref("default");
const ruleFormRef = ref<FormInstance>();
const ruleForm = reactive({
  region: "",
  region1: "",
  region2: "",
  region3: "",
  region4: "",
  region5: "",
  region6: "",
  region7: "",
  region8: "",
  region9: "",
  region10: "",
  region11: "",
  region12: "",
  region13: "",
  region14: "",
  region15: "",
  region16: "",
  region17: "",
  region18: "",
});

const rules = reactive<FormRules>({
  region: [
    {
      required: true,
      message: "Please select Activity zone",
      trigger: "change",
    },
  ],
  region1: [
    {
      required: true,
      message: "Please select Activity zone",
      trigger: "change",
    },
  ],
});

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log("submit!");
    } else {
      console.log("error submit!", fields);
    }
  });
};

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
};
// 表格
const tableData = [
  {
    date: "2016-05-03",
    name: "Tom",
    address: "No. 189, Grove St, Los Angeles",
  },
];
const handleClick = (xid) => {
  deleteCourseList({ id: xid }).then((res:any) => {
    if (res.code == 0) {
      findCourseList({ startDate: "10-17", coachId: value.value }).then(
        (res) => {
          state.tableData = res;
          console.log(state.tableData);
        }
      );
    }
  });
};
// 查询
const query = () => {
  console.log(value.value);
  findCourseList({ startDate: "10-17", coachId: value.value }).then((res) => {
    console.log(res);
    state.tableData = res;
    console.log(state.tableData);
  });
};
</script>
<style scoped>
.lessons-padding1 {
  padding: 10px 0;
}
.List-title {
  padding: 10px 5px;
  background-color: #f3f3f3;
}
.line-break {
  display: block;
  color: rgb(169, 168, 168);
}
.border {
  padding: 10px;
  border-radius: 5px;
  background-color: #ecf5ff;
  border: 1px solid #cccccc;
}
.button-text-color {
  background-color: #fefefe !important;
  color: black !important;
  border: 1px solid #cccccc;
}
.button-text-color a {
  color: black !important;
}
.button-text-color2 {
  background-color: #409eff !important;
  color: white !important;
}
.button-text-color3 {
  background-color: #409eff;
  color: white;
}
</style>
